#include "widget.h"
#include "ui_widget.h"
#include <QTimer>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    timer = new QTimer(this);

    ui->lineEdit->setEchoMode(QLineEdit::Password);
    ui->lineEdit->setPlaceholderText("请输入密码");
    ui->lineEdit->setClearButtonEnabled(true);

    ui->lineEdit_2->setEchoMode(QLineEdit::Password);
    ui->lineEdit_2->setPlaceholderText("密码确认");
    ui->lineEdit_2->setClearButtonEnabled(true);
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_lineEdit_2_textEdited(const QString &arg1)
{
    (void) arg1;
    const QString& s1 = ui->lineEdit->text();
    const QString& s2 = ui->lineEdit_2->text();
    if(!s1.isEmpty() && !s2.isEmpty())
    {
        ui->pushButton->setEnabled(true);
    }
}

void Widget::on_pushButton_clicked()
{
    const QString& s1 = ui->lineEdit->text();
    const QString& s2 = ui->lineEdit_2->text();
    if(s1 == s2)
    {
        ui->label->setText("密码通过！");
        connect(timer, &QTimer::timeout, this, &Widget::handle);
        timer->start(3000);
    }
    else
    {
        ui->label->setText("密码不一致！！！");
        connect(timer, &QTimer::timeout, this, &Widget::handle);
        timer->start(3000);
    }
}

void Widget::handle()
{
    ui->label->setText("");
    timer->stop();
}
